﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using BUS;
using DTO;
namespace GUI
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
        public static string user;
        private void Form1_Load(object sender, EventArgs e)
        {
            user = frmDangNhap.user;
            this.xinchao.Text = "Xin chào: " + user;
            Screen scr = Screen.PrimaryScreen;
            int with = scr.WorkingArea.Width;
            int hight = scr.WorkingArea.Height;
            this.Size = new Size(with,hight);
            this.StartPosition = FormStartPosition.Manual;
            XoaFormChidren();
            //frmDonHangSapGiao fr = new frmDonHangSapGiao();
            //fr.MdiParent = this;
            //fr.Show();
        }
        private void TKHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmTraCuuKhachHang frm = new frmTraCuuKhachHang();
            frm.MdiParent = this;
            frm.Show();
        }

        private void saoChépDựPhòngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog s = new SaveFileDialog();
            s.Filter = "(*.bak)|*.bak";
            if (s.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string sql = "backup database QLCHH to disk='" + s.FileName.ToString() + "'";
                    DataService dv = new DataService();
                    SqlCommand cm = new SqlCommand(sql);
                    dv.Load(cm);
                    MessageBox.Show("Sao Lưu thành công");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void khôiPhụcDữLiệuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.Filter = "(*.bak)|*.bak";
            if (op.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string sql = "use master restore database QLCHH from disk='" + op.FileName.ToString() + "'";
                    DataService dv = new DataService();
                    SqlCommand cm = new SqlCommand(sql);
                    dv.Load(cm);
                    MessageBox.Show("Phục hồi dữ liệu thành công");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Có lỗi xảy ra, không thể khôi phục cơ sở dữ liệu, vui lòng kiểm tra lại!");
                }
            }
        }

        private void TKHHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmThongKe frm = new frmThongKe();
            frm.MdiParent = this;
            frm.Show();
        }

        private void toolStripButtonTNCC_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDonHangSapGiao frm = new frmDonHangSapGiao();
            frm.MdiParent = this;
            frm.Show();
        }

        private void THHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmTraCuuHoaDon frm = new frmTraCuuHoaDon();
            frm.MdiParent = this;
            frm.Show();
        }

        private void TNCCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmTraCuuPhieuNhapHang frm = new frmTraCuuPhieuNhapHang();
            frm.MdiParent = this;
            frm.Show();
        }

       //-----HAI---
       
        private void DNToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDangNhap f = new frmDangNhap();
            f.ShowDialog();
        }

        private void DXToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDoiMatKhau f = new frmDoiMatKhau();
            f.MdiParent = this;
            f.Show();
        }

        private void ThoatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void KHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmKhachHang f = new frmKhachHang();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripButtonKH_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmKhachHang f = new frmKhachHang();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripButtonHH_Click_1(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmMatHang f = new frmMatHang();
            f.MdiParent = this;
            f.Show();
        }

        private void HHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmMatHang f = new frmMatHang();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripButtonNCC_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmNhaCungCap f = new frmNhaCungCap();
            f.MdiParent = this;
            f.Show();
        }

        private void DNToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDangNhap f = new frmDangNhap();
            f.MdiParent = this;
            f.Show();
        }

        private void DXToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDoiMatKhau f = new frmDoiMatKhau();
            f.MdiParent = this;
            f.Show();
        }

        private void ThoatToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void toolStripButtonKH_Click_1(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmKhachHang f = new frmKhachHang();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripButtonNCC_Click_1(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmNhaCungCap f = new frmNhaCungCap();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripButtonHH_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmMatHang f = new frmMatHang();
            f.MdiParent = this;
            f.Show();
        }

        private void KHToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmKhachHang f = new frmKhachHang();
            f.MdiParent = this;
            f.Show();
        }

        private void NCCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmNhaCungCap f = new frmNhaCungCap();
            f.MdiParent = this;
            f.Show();
        }

        private void HHToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmMatHang f = new frmMatHang();
            f.MdiParent = this;
            f.Show();
        }


     
        //-------END HAI-----
        // ----------- LOI ---------------------
        private void toolStripButtonPDH_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDonDatHang fr = new frmDonDatHang();
            fr.MdiParent = this;
            fr.Show();
        }

        private void toolStripButtonPBH_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmHoaDonBanHang fr = new frmHoaDonBanHang();
            fr.MdiParent = this;
            fr.Show();
        }

        private void BHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmHoaDonBanHang fr = new frmHoaDonBanHang();
            fr.MdiParent = this;
            fr.Show();
        }

        private void DHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDonDatHang fr = new frmDonDatHang();
            fr.MdiParent = this;
            fr.Show();
        }

        private void toolStripDanhSach_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDanhSachDonHang fr = new frmDanhSachDonHang();
            fr.MdiParent = this;
            fr.Show();
        }
        private void XoaFormChidren()
        {
            foreach (Form f in MdiChildren)
            {
                f.Close();
            }
        }
        
        // --------------------------------------------
        //--------------KIM--------------
        private void toolStripButtonPNH_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDonNhapHang frm = new frmDonNhapHang();
            frm.MdiParent = this;
            frm.Show();
        }


        private void NHToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDonNhapHang frm = new frmDonNhapHang();
            frm.MdiParent = this;
            frm.Show();
        }

        private void SCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDonTraHang frm = new frmDonTraHang();
            frm.MdiParent = this;
            frm.Show();
        }
        private void toolStripButtonPTH_Click(object sender, EventArgs e)
        {
            XoaFormChidren();
            frmDonTraHang frm = new frmDonTraHang();
            frm.MdiParent = this;
            frm.Show();
        }
        //END------------------------------
    }
}
